package com.jeasonzhao.commons.data;

import java.io.Serializable;

public class Position implements Serializable
{
    private static final long serialVersionUID = 1L;
    private int rowIndex = 0;
    private int colIndex = 0;
    public Position()
    {
        super();
    }

    public Position(int row,int col)
    {
        this.rowIndex = row;
        this.colIndex = col;
    }

    public Position(Position p)
    {
        this.rowIndex = null == p ? 0 : p.rowIndex;
        this.colIndex = null == p ? 0 : p.colIndex;
    }

    public int getColIndex()
    {
        return colIndex;
    }

    public int getRowIndex()
    {
        return rowIndex;
    }

    public void setColIndex(int colIndex)
    {
        this.colIndex = colIndex;
    }

    public void setRowIndex(int rowIndex)
    {
        this.rowIndex = rowIndex;
    }

    public boolean isTopLeftOf(Range r)
    {
        return r == null ? false : r.isTopLeft(this.rowIndex,this.colIndex);
    }

    public boolean isIn(Range r)
    {
        return null == r ? false : r.contains(this.rowIndex,this.colIndex);
    }

    public Range createRange(int rowSpan,int colSpan)
    {
        Range r = new Range(this);
        return r.span(rowSpan,colSpan);
    }
}
